package com.glory.hikvisionmobile.adapter;

import android.widget.CheckBox;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.glory.hikvisionmobile.R;
import com.glory.hikvisionmobile.bean.LotPauseOrGo.LotPauseListBean;
import java.util.List;

public class LotGoListAdapter extends BaseQuickAdapter<LotPauseListBean, BaseViewHolder> {

    private int selectorPos = -1;

    public LotGoListAdapter(@Nullable List<LotPauseListBean> data) {
        super(R.layout.adapter_param_list,data);
    }

    @Override
    protected void convert(BaseViewHolder helper, LotPauseListBean item) {

        helper.setText(R.id.tvItem1,item.getHoldReason());
        helper.setText(R.id.tvItem2,item.getHoldUser());
        helper.setText(R.id.tvItem3,item.getHoldOwner());
        helper.setVisible(R.id.cbLayout,true);
        CheckBox pauseCb = helper.getView(R.id.pauseCb);
        int position = helper.getAdapterPosition();
        pauseCb.setChecked(item.isCheck());
        helper.setGone(R.id.tvItem4,false);
        helper.setGone(R.id.tvItem5,false);
        pauseCb.setOnClickListener(view -> {
            if (selectorPos == -1){
                item.setCheck(true);
                selectorPos = position;
            }else if (selectorPos != position){
                getData().get(selectorPos).setCheck(false);
                notifyItemChanged(selectorPos);
                item.setCheck(true);
                selectorPos = position;
            }
            notifyItemChanged(position);
        });

    }

    public int getSelectorPos(){
        return selectorPos;
    }

    public void setSelectorPos(int position){
        this.selectorPos = position;
    }

}
